<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 300px;
            height: 300px;
            background: pink;
            text-align: center;
            line-height: 300px;
        }
        .box .num{
            font-size:50px;
        }
    </style>
</head>
<body>
    <div class="box">
        <span class="num">0</span>
    </div>

    <script>
        var box = document.querySelector(".box");
        var num = document.querySelector(".num");
        var count = 0;

        function throttle( func ,wait , options ){
            if (!options) {
                options = {};
            }

            var context = null;
            var args = null;
            var old = 0;
            var timeout = null;

            var later = function(){
                func.apply( context, args );
                timeout = null;

                now = new Date().getTime();
                old = now;
            }

            var throttled = function(){
                context = this;
                args = arguments;

                var now = new Date().getTime();

                if( options.leading === false && !old ){
                    old = now;
                }

                if( now - old > wait ){
                    func.apply( context , args );
                    old = now;
                    if( timeout ){
                        clearTimeout( timeout );
                        timeout = null;
                    }
                }else if( !timeout && options.trailing !== false ){
                    timeout = window.setTimeout( later , wait );
                }
            }

            throttled.cancel = function() {
                clearTimeout(timeout);
                old = 0;
                timeout = null;
            }

            return throttled;
        }

        box.onmousemove = throttle( function(){
            count++;
            num.innerText = count;
        }, 1000 , {leading:true,trailing: false } );;
    </script>
</body>
</html>